package com.snopy.leetcode.offer;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Question03
 * @description 数组中的重复数字
 *
 * @email 77912204@qq.com
 * @date 2022/04/02 23:32
 */
public class Question03 {

    public static void main(String[] args) {
        int[] nums = new int[]{2, 3, 1, 0, 2, 5, 3};
        int num = findRepeatNumber(nums);
        System.out.println(num);
    }
    public static int findRepeatNumber(int[] nums) {
        for(int i=0;i<nums.length;i++){
            int k = nums[i];
            if (k < 0){
                k += nums.length;
            }
            if (nums[k] < 0){
                return k;
            }
            nums[k] -=  nums.length;
        }
        return -1;
    }
}

